/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package algoritmosgenetico;

/**
 *
 * @author Administrador
 */
public class CalcularSolucion {
    private double costo;
    private double costoFijo;
    private double costoVariable;
    private int[] sol;

    public CalcularSolucion(int[] s, int[] cf, double[][] cv){
        sol=s;
        calcularCostos(cf, cv);
    }

    public void calcularCostos(int[] cf, double[][] cv){
        costoFijo=0;
        for(int i=0;i<sol.length;++i){
            costoFijo=costoFijo+sol[i]*cf[i]*1d;
        }
        costoVariable=0;
        for(int i=0;i<cv.length;++i){
            double[] caux=new double[cv[i].length];
            double cmax=0;
            for(int j=0;j<cv[i].length;++j){
                caux[j]=cv[i][j];
                cmax=cmax+caux[j];
            }
            for(int j=0;j<cv[i].length;++j){
                caux[j]=(sol[j]==0)?cmax:cv[i][j];
            }
            double cmin=calcularMinimo(caux);
            //System.out.println((i+1)+" "+cmin);
            costoVariable=cmin+costoVariable;
        }
        costo=costoFijo+costoVariable;

    }

    public double calcularMinimo(double[] ct){
     double min=0;
     java.util.Arrays.sort(ct);
     min=ct[0];
     return min;
    }

    /**
     * @return the costo
     */
    public double getCosto() {
        return costo;
    }

    /**
     * @return the costoFijo
     */
    public double getCostoFijo() {
        return costoFijo;
    }

    /**
     * @return the costoVariable
     */
    public double getCostoVariable() {
        return costoVariable;
    }

     
}
